package com.huitone.gddw.service.impl.system;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huitone.gddw.dao.entity.UserDept;
import com.huitone.gddw.dao.system.IUserDeptDao;
import com.huitone.gddw.service.system.IUserDeptService;
import com.huitone.gddw.utils.SysLoginUtil;

/**
 * 用户归属单位 接口实现类
 * @author wuluodan
 *
 */
@Service
public class UserDeptService implements IUserDeptService {

	@Autowired
	private IUserDeptDao userDeptDao;

	@Override
	public UserDept getByUserId(String userId) {
		return userDeptDao.getByUserId(userId);
	}
	
	@Override
	public void save(UserDept entity) {
		entity.setInsertTime(new Date());
		entity.setInsertStaffId(SysLoginUtil.getLoginUserId());
		entity.setLastModTime(entity.getInsertTime());
		entity.setLastModStaffId(entity.getInsertStaffId());
		userDeptDao.insertSelective(entity);
	}
	
	@Override
	public void save(String userId, String deptId) {
		UserDept userDept = new UserDept();
		userDept.setUserId(userId);
		userDept.setDeptId(deptId);
		this.save(userDept);
	}

	@Override
	public void update(UserDept entity) {
		userDeptDao.updateByPrimaryKey(entity);
	}

	@Override
	public void delAllByUserId(String userId) {
		userDeptDao.delByUserId(userId);
	}

	@Override
	public List<UserDept> getByDeptId(String deptId) {
		return userDeptDao.getByDeptId(deptId);
	}
	
}
